import { Button, Checkbox, Form, Input } from "antd";
import type { FormProps } from "antd";
import React from "react";

export default function FormTest() {
  type FieldType = {
    username?: string;
    password?: string;
    remember?: string;
  };

  const onFinish: FormProps<FieldType>["onFinish"] = (values) => {
    console.log("Success:", values);
  };

  return (
    <div>
      <Form
        name="basic"
        labelCol={{ span: 8 }} // 文字宽度
        wrapperCol={{ span: 10 }} // 表单宽度
        style={{ maxWidth: 600 }} // 最大宽度
        initialValues={{ remember: true }}
        onFinish={onFinish} // 点击submit按钮时触发
      >
        <Form.Item<FieldType>
          label="Username"
          name="username"
          rules={[{ required: true, message: "Please input your username!" }]}
        >
          <Input />
        </Form.Item>

        <Form.Item<FieldType>
          label="Password"
          name="password"
          rules={[
            { required: true, message: "Please input your password!" },
            {pattern:/^[a-zA-Z]\d{5}$/, message:'密码不合法'}
          ]}
        >
          <Input.Password />
        </Form.Item>
        

        <Form.Item<FieldType>
          name="remember"
          valuePropName="checked"
          label={null} // label 标签的文本，当不需要 label 又需要与冒号对齐，可以设为 null
        >
          <Checkbox>Remember me</Checkbox>
        </Form.Item>

        <Form.Item label={null}>
          <Button type="primary" htmlType="submit">
            Submit
          </Button>
        </Form.Item>
      </Form>
    </div>
  );
}
